﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 生命体征测试仪
{
    public partial class formInputPass : formBase
    {
        public formInputPass()
        {
            InitializeComponent();
            strInput = "";
            bOK = false;
            skinTextBox1.Text = "";
            numKey1.NumKey_BtnClicked += new 生命体征测试仪.NumKey.BtnClickHandle(InputNum);
        }
        public bool bPoint;
        int min;
        int max;
        public formInputPass(string strTitle, string str1, string remind,int _min,int _max)
        {
            InitializeComponent();
            strInput = "";
            skinTextBox1.IsSystemPasswordChar = false;
            skinLabel1.Text = strTitle;
            skinTextBox1.Text = "";
            bOK = false;
            numKey1.NumKey_BtnClicked += new 生命体征测试仪.NumKey.BtnClickHandle(InputNum);
            if (str1 != "")
            {
                numKey1.Set1(str1);
                if (str1 == ".")
                    bPoint = true;
            }
            skinLabel2.Text = remind;
            min = _min;
            max = _max;
        }
        public string strInput;
        public bool bOK;
        private void skinButton1_Click(object sender, EventArgs e)
        {
            strInput = skinTextBox1.Text;
            if (bPoint)
            {
                float f;
                try
                {
                    f = float.Parse(strInput);
                }
                catch //(System.Exception ex)
                {
                    MessageBox.Show("输入数据格式不正确，请重新输入");
                    return;
                }
                if (f > max || f < min)
                {
                    MessageBox.Show("输入数据范围有误，请重新输入");
                    return;
                }
            }
            
            bOK = true;
            this.Close();            
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            //bOK = true;
            this.Close();
        }
        void InputNum(int n)
        {

            this.Invoke((EventHandler)(delegate
            {
                if (n == -1)
                    skinTextBox1.Text = "";
                else if (n == -2)
                {
                    if (bPoint)
                        skinTextBox1.Text += ".";
                    else
                    {
                        try
                        {
                            skinTextBox1.Text = skinTextBox1.Text.Substring(0, skinTextBox1.Text.Length - 1);
                        }
                        catch// (System.Exception ex)
                        {

                        }
                    }                    
                }
                else
                {
                    skinTextBox1.Text += n.ToString();
                }                
            }));
        }
    }
}
